package com.example.shop.fgo.task.upload.model;

import com.example.shop.fgo.task.common.model.Task;

import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;

/**
 * Created by Administrator on 2017/2/20.
 */
@Table(name = "UploadTask")
public class UploadTask extends Task {
    public static final int TYPE_DA=110;
    public static final int TYPE_XIAO=120;
    @Column(name = "type")
    public int type=TYPE_XIAO;

    @Column(name = "filePath")
    public String filePath;

    @Column(name = "url")
    public String url;


    @Column(name = "pid")
    public String pid;


    public int decision=NOT_YET;

    public static final int NOT_YET=333;
    //设置文件覆盖不覆盖
    public static final int FG=111;
    public static final int BUFG=222;

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    @Override
    public void setTotalSize(int totalSize) {
        super.setTotalSize(totalSize);
        //如果总大小大于50k，我们判定为大文件，否则为小文件
        if (totalSize>1024*50){
            type=TYPE_DA;
        }else {
            type=TYPE_XIAO;
        }
    }

    public String getUrl() {
        return url;
    }

    /**
     * 必须在setTotalSize之后调用
     * @param sdEntity
     * @param cidNow
     */
    public void setUrl(SDEntity sdEntity,String cidNow) {
        StringBuilder stringBuilder=new StringBuilder();

        if (totalSize>1024*50){
            type=TYPE_DA;
            stringBuilder.append("http://101.200.183.103:9999/a1/resumeUpload?");
        }else {
            type=TYPE_XIAO;
            stringBuilder.append("http://101.200.183.103:9999/a1/upload?");

        }
        stringBuilder.append("sha1=");
        stringBuilder.append(sha1);
        stringBuilder.append("&");

        stringBuilder.append("size=");
        stringBuilder.append(totalSize);
        stringBuilder.append("&");


        stringBuilder.append("pid=");
        stringBuilder.append(cidNow);

        this.url=stringBuilder.toString();
    }


}
